<template>
	<view class="uni_box">
		<!-- #ifdef APP-PLUS -->
		<!-- <view class="immerse"></view> -->
		<!-- #endif -->
		<view class="newcontent">
			<!-- 头部 -->
			<Nheader @leftClick="leftClick" @connectWallet="connectWallet" :cont="cont" @gettantwo="gettantwo"></Nheader>
			<image class="mban" src="/static/bgthree.jpg" />
			<view class="content">
				<view class="twen">
					<text class="wentit">{{$t('i.quanqiu')}}</text>
					<text class="wentit" :style="{ fontSize: yuyan == 'en' ? '23px' : '28px' }">{{$t('i.ptai')}}</text>
					<text class="wenmiao">{{$t('i.di')}}</text>
					<view class="adress" @click="copy('123')">0x4Df510C1C9dA1Bfd99256dD1f</view>
				</view>
				<image class="Frame2" src="/static/Frame2.png" />
				<view class="gouview">
					<view class="gouitem">
						<text class="dajie">{{$t('i.dajie')}}</text>
						<text class="danum"><text class="usdt">1000</text>USDT</text>
						<view class="rengou gou">{{$t('i.rengou')}}</view>
					</view>
					<view class="gouitem ml">
						<text class="dajie">{{$t('i.xioajie')}}</text>
						<text class="danum"><text class="usdt">500</text>USDT</text>
						<view class="rengou">{{$t('i.yixiao')}}</view>
					</view>
				</view>
			</view>
			<view class="yupop" v-if="zshow">
				<view class="popitem " :class="yuyan=='zh'?'pactive':''" @click="getyuyin('zh')">
					<text class="ptit">中文</text>
					<image class="gou" src="/static/gou.png" />
				</view>
				<view class="popitem" :class="yuyan=='en'?'pactive':''" @click="getyuyin('en')">
					<text class="ptit">English</text>
					<image class="gou" src="/static/gou.png" />
				</view>
				<view class="popitem" :class="yuyan=='hh'?'pactive':''" @click="getyuyin('hh')">
					<text class="ptit">한국어</text>
					<image class="gou" src="/static/gou.png" />
				</view>
				
			</view>
		</view>
</view>
</template>

<script>
import { connectMetamask, buy, ADDRESS0, getTotalIn, getRewardAlreadyPaid, getEarned, getLPReward, getTokenReward,isHolder } from "@/utils/dapp.js"
import { defaultTo, path, take, takeLast } from "ramda"
import { DateTime } from 'luxon'
import tryCatch from "ramda/src/tryCatch"
import { ethers } from "ethers"
import Nheader from '@/components/Nheader/Nheader'
export default {
	data() {
		return {
			bgcolor: '#fff',
			checked: false,
			border: false,
			type: '1',
			show: false,
			keywords: '',
			list: [],
			hbg: '#0d0e0f',
			cont: 'Connect Wallet',
			typeindex: 0,
			lp_amount:"",
			totalIn:0,
			alreadyPaid:0,
			in_percent:0,
			earned:0,
			iszhan: false,
			zhaninfo: {},
			applist: [],
			lshow: false,
			zshow: false,
			yuyan:'zh'
		}
	},
	components: {
		Nheader
	},
	computed: {
		qshu(){
			return this.$t('i.qshu')
		},
		shuwu(){
			return this.$t('i.shuwu')
		}
	},

	mounted() {

	},
	async onLoad() {
		// const addr = await connectMetamask()
		// if (typeof addr === 'string') {
		// 	this.cont = take(5, addr) + '...' + takeLast(3, addr) + ' '
			
		// 	const tlin = await getTotalIn()
		// 	this.totalIn = Number(Number(tlin).toFixed(3))
		
		// 	const earn = await getEarned()
		// 	this.earned = earn
			
		// 	const alreadyPaid = await getRewardAlreadyPaid()
		// 	this.alreadyPaid = (Number(alreadyPaid) + Number(earn)).toFixed(3)
			
			
		// 	const in_percent =  Number(tlin) == 0 ? 0: ((Number(alreadyPaid) + Number(earn))* 100) / Number(tlin)
		// 	this.in_percent = Math.floor(in_percent)
			
		// }
	},
	async onShow() {
		if(uni.getStorageSync('locale')){
			this.yuyan = uni.getStorageSync('locale')
		}
	},
	onReachBottom: function () {
	},
	methods: {
		typeClick(e) {
			this.type = e
		},
		async cancelAppo() {
			console.log(33333)
		},
		async getLp11() {
			const res = await getLPReward()
			console.log(res)
			if(res){
			const tlin = await getTotalIn()
			this.totalIn = Number(Number(tlin).toFixed(3))
		
			const earn = await getEarned()
			this.earned = earn
			
			const alreadyPaid = await getRewardAlreadyPaid()
			this.alreadyPaid = (Number(alreadyPaid) + Number(earn)).toFixed(3)
			
			const in_percent =  Number(tlin) == 0 ? 0: ((Number(alreadyPaid) + Number(earn))* 100) / Number(tlin)
			this.in_percent = Math.floor(in_percent)
			}
		},
		async getToken() {
			const res = await getTokenReward()
			if(res){
				const tlin = await getTotalIn()
				this.totalIn = Number(Number(tlin).toFixed(3))
			
				const earn = await getEarned()
				this.earned = earn
				
				const alreadyPaid = await getRewardAlreadyPaid()
				this.alreadyPaid = (Number(alreadyPaid) + Number(earn)).toFixed(3)
				
				const in_percent =  Number(tlin) == 0 ? 0: ((Number(alreadyPaid) + Number(earn))* 100) / Number(tlin)
				this.in_percent = Math.floor(in_percent)	
			}
		},
		async addliq() {			
			const url = new URL(window.location.href);
			const parent = url.searchParams.get("i");
			const p = parent ? parent:  ADDRESS0
			
			console.log(this.lp_amount)
			console.log(p)
			
			const res = await buy(this.lp_amount, p)
			if(res){
				const tlin = await getTotalIn()
				this.totalIn = Number(tlin)
			}
			
		},
		async connectWallet() {
			const addr = await connectMetamask()
			console.log(addr)
			if (typeof addr === 'string') {
				this.cont = take(5, addr) + '...' + takeLast(3, addr) + ' '
			}
		},
		async scan() {
		},
		async getLogintwo(code) {
			let res = await this.$u.api.miniapplogin({
				code: code
				// userid:uni.getStorageSync('userid')
			});
			console.log(res.userinfo)
			this.seeion_key = res.seeion_key
			uni.setStorageSync('token', res.userinfo.token)
			// uni.setStorageSync('userid',res.Data.userinfo.userid)
			if (res.userinfo.mobile == '' || !res.userinfo.mobile) {
				//弹出登录
				this.loginshow = true
			} else {
				this.getInit()
			}
			// // console.log(res)
			// console.log(res.Data)
		},

		async getLun() {
			let res = await this.$u.api.banner({
			});
			console.log(res)
		},
		async getList() {//列表数据
			let res = await this.$u.api.project({
				pagesize: this.limit,
				page: this.page,
				keywords: this.keywords
			});
			console.log(res)
			this.last_page = res.lastpage;
			let list = res.list;
			this.list = this.page == 1 ? list : [...this.list, ...list];
			// console.log(this.list)
			if (this.page >= this.last_page) {
				this.status = 'nomore';
			}

		},
		loadmore() {
			let page = this.page;
			// let last_page = this.last_page;
			if (this.status == 'loadmore') {
				this.page++;
				this.getList();
			}
		},
		confirm(e) {
			console.log(e)
		},
		swchange(e) {
			console.log(e)
			if (!e) {
				this.bgcolor = '#fff'
			} else {
				this.bgcolor = '#0d0e0f'
			}
			console.log(bgcolor)
		},
		async typeClick1(item, index) {
			this.typeindex = index
			this.zhaninfo = item
			this.iszhan = false

			try {
				const chain_id = await window.ethereum.request({ method: "eth_chainId" })
				if (chain_id != item.chainid) {
					await window.ethereum.request({
						method: 'wallet_switchEthereumChain',
						params: [{ chainId: item.chainid }]
					});
				}
			} catch (e) {
				//TODO handle the exception
			}


		},
		leftClick() {
			console.log("+++")
			this.lshow = true
		},
		getyuyin(e) {
			this.yuyan = e
			this.switchLang(this.yuyan)
		},
		switchLang(e) {
			this.$i18n.locale = e
			// console.log(this.$i18n.locale)
			uni.setStorageSync('locale', e)
			this.zshow = false
			// this.$store.commit('getwen');
		},
		gettantwo(){
			if(!this.zshow){
				this.zshow = true 
			}else{
				this.zshow = false 
			}
			
		},



	}
}
</script>

<style lang="scss" scoped>
page,
html {}

.newcontent {
	min-height: 100vh;
	background-color: #080808;
	
	.content{
		position: relative;
	}
	.mban{
		width: 100%;
		height: 100%;
		// margin: -30px auto 0;
		position: absolute;
		top: 0;
		min-height: 100vh;

	}
	.twen{
		margin: 80rpx 50rpx 30rpx;
		.wentit{
			color: #fff;
			font-size: 28px;
			font-weight: 600;
			display: block;
			text-align: center;
		}
		.wenmiao{
			font-size: 12px;
			color: #fff;
			opacity: 0.5;
			font-weight: 400;
			display: block;
			text-align: center;
			margin: 30rpx 0 20rpx;
		}
		.adress{
			background-color: #FFFFFF1A;
			width: 100%;
			display: inline-block;
			align-items: center;
			text-align: center;
			justify-content: center;
			padding: 10rpx;
			border-radius: 4px;
			color: #fff;
			font-size: 12px;
			font-weight: 400;
			white-space: nowrap;
			/* 3. 隐藏超出容器的文本内容 */
			overflow: hidden;
			/* 4. 用省略号替代超出的文本 */
			text-overflow: ellipsis;
		}
	}
	.Frame2{
		width: 100%;
		height: 200px;
		position: relative;
	}
	.gouview{
		position: relative;
		display: flex;
		flex-direction: row;
		padding: 0 40rpx;
		margin-top: -63px;
		margin-bottom: 30rpx;
		.gouitem{
			width: 48%;
			height: 200px;
			background-color: rgba(255,255,255,0.1);
			border: 2px solid rgba(255,255,255,0.35);
			border-radius: 30rpx;
			position: relative;
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			.dajie{
				font-size: 14px;
				color: rgba(255,255,255,0.75);
				display: block;
				margin-bottom: 4px;
			}
			.danum{
				color: #fff;
				font-size: 14px;
				font-weight: 400;
				.usdt{
					font-size: 28px;
					font-weight: 500;
					display: inline-block;
					margin-right: 6px;
				}
			}
			.rengou{
				margin-top: auto;
				width: 100%;
				background-color: rgba(255,255,255,0.1);
				border-radius: 10rpx;
				height: 32px;
				display: flex;
				align-items: center;
				justify-content: center;
				color: rgba(255,255,255,0.5);
			}
			.gou{
				background-color: #FFA100;
				color: #000;

			}
		}
		
	}
}
.yupop{
	// width: 120px;
	min-width: 140px;
	position: absolute;
	top: 58px;
	right: 30rpx;
	background-color: rgba(51, 51, 51, 0.802);
	z-index: 100;
	border-radius: 30rpx;
	display: flex;
	flex-direction: column;
	padding: 10rpx 0;
	.popitem{
		height: 45px;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0 20px;
		position: relative;
		.ptit{
			color: #fff;
			font-size: 14px;
			font-weight: 400;
		}
		.gou{
			width: 23px;
			height: 23px;
			margin-left: 20px;
			position: absolute;
			right: 15px;
			display: none;
		}
	}
	.pactive{
		.gou{
			display: inline-block;
		}
		.ptit{
			color: #FFA100;
		}
	}
}
</style>
